﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Maticsoft.DBUtility;

namespace ElingOA6_DSJCJ.DAL
{
    /// <summary>
    /// 人员信息DAL
    /// </summary>
    public class HREmpl
    {
       
        /// <summary>
        /// 根据员工编号从V_HREmpl中获得数据列表
        /// <creator>wangl</creator>
        /// <date>2013-07-18</date>
        /// </summary>
        /// <param name="emplNo">员工</param>
        /// <param name="entityNo">公司编号</param>
        /// <returns>DataSet对象</returns>
        public DataSet GetEmplFromViewByEmplNo(string emplNo, string entityNo)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FEntityNo, FEmplNo, FEmpName, FDeptNo, FDeptName ,FPositionNo,FIsMainPosition ");
            strSql.Append(" FROM v_HREmpl ");
            strSql.Append(" where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo");
            SqlParameter[] parameters = {
                   new SqlParameter("@FEntityNo",SqlDbType.VarChar,50),
                   new SqlParameter("@FEmplNo",SqlDbType.NVarChar,50)};
            parameters[0].Value = entityNo;
            parameters[1].Value = emplNo;
            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 获取人员名称
        /// <creator>wangl</creator>
        /// <date>2013-09-25</date>
        /// </summary>
        /// <param name="entityNo">组织机构编号</param>
        /// <param name="empNo">人员编号</param>
        /// <returns>人员名称</returns>
        public string GetEmpName(string entityNo, string empNo)
        {
            string strSql = "select  top 1 FEmpName from t_HREmpl where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo";
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
            parameters[0].Value = entityNo;
            parameters[1].Value = empNo;

            object obj = DbHelperSQL.GetSingle(strSql, parameters);
            if (null != obj)
            {
                return obj.ToString();
            }
            else
            {
                return string.Empty;
            }
        }
        /// <summary>
        /// 获取是否需要考勤
        /// <creator>chenly</creator>
        /// <date>2014-03-11</date>
        /// </summary>
        /// <param name="entityNo">组织机构编号</param>
        /// <param name="empNo">人员编号</param>
        /// <returns>人员名称</returns>
        public string GetIsAttendance(string entityNo, string empNo)
        {
            string strSql = "select  top 1 FIsAttendance from t_HREmpl where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo";
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
            parameters[0].Value = entityNo;
            parameters[1].Value = empNo;

            object obj = DbHelperSQL.GetSingle(strSql, parameters);
            if (null != obj)
            {
                return obj.ToString();
            }
            else
            {
                return string.Empty;
            }
        }
        /// <summary>
        /// 获取考勤IP
        /// <creator>chenly(wangl引用)</creator>
        /// <date>2014-03-11</date>
        /// </summary>
        /// <param name="entityNo">组织机构编号</param>
        /// <param name="empNo">人员编号</param>
        /// <returns>人员名称</returns>
        public string GetAttendanceIpAddress(string entityNo, string empNo)
        {
            string strSql = "select  top 1 FAttendanceIpAddress from t_HREmpl where FEntityNo=@FEntityNo and FEmplNo=@FEmplNo";
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15)};
            parameters[0].Value = entityNo;
            parameters[1].Value = empNo;

            object obj = DbHelperSQL.GetSingle(strSql, parameters);
            if (null != obj)
            {
                return obj.ToString();
            }
            else
            {
                return string.Empty;
            }
        }
        /// <summary>
        /// 设置考勤IP地址绑定
        /// </summary>
        /// <param name="entityNo"></param>
        /// <param name="empNo"></param>
        /// <param name="attendanceIpAddress"></param>
        public void UpdateAttendanceIpAddress(string entityNo, string empNo,string attendanceIpAddress)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("UPDATE t_HREmpl SET FAttendanceIpAddress=@FAttendanceIpAddress");
            strSql.Append(" WHERE FEntityNo=@FEntityNo and FEmplNo=@FEmplNo");
            SqlParameter[] parameters = {
					new SqlParameter("@FEntityNo", SqlDbType.NVarChar,15),
					new SqlParameter("@FEmplNo", SqlDbType.NVarChar,15),
                    new SqlParameter("@FAttendanceIpAddress", SqlDbType.NVarChar,16)
                };
            parameters[0].Value = entityNo;
            parameters[1].Value = empNo;
            parameters[2].Value = attendanceIpAddress;
            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 获取生日人员
        /// <creator>wangl</creator>
        /// <date>2014-10-27</date>
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public DataSet GetListBirth(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT FEmpName,FBirthday FROM dbo.v_HREmpl ");
            if (strWhere != "")
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append("ORDER BY FDeptSeq,FSeq");
            return DbHelperSQL.Query(strSql.ToString());
        }
    }
}

